package com.eight.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.eight.mapper.LoginInfoMapper;
import com.eight.pojo.SysLogininfor;
import com.eight.service.LoginLogService;
import com.eight.vo.ComResult;
import com.eight.vo.LoginLogVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Description: 登录日志的业务层
 * @Author: Van.Planifolia
 * @CreateTime: 2023-02-27  19:57
 * @Version: 1.0
 */
@Service("loginLogService")
public class LoginLogServiceImpl extends ServiceImpl<LoginInfoMapper, SysLogininfor> implements LoginLogService {
    @Resource
    private LoginInfoMapper loginInfoMapper;

    /**
     * 模糊分页查询
     *
     * @param sysLogininfor 查询条件
     * @param pageIndex     页面索引
     * @param pageSize      页面大小
     * @return 查询的结果
     */
    @Override
    public ComResult fuzzySearch(LoginLogVo sysLogininfor, Integer pageIndex, Integer pageSize) {
        Page<SysLogininfor> page = new Page<>(pageIndex, pageSize);
        page = loginInfoMapper.fuzzySearch(page,sysLogininfor);
        return new ComResult(2000, "查询成功", page);
    }

    /**
     * 查询当前用户最近的登录信息
     *
     * @param username 用户的名字
     * @return 登录信息
     */
    @Override
    public ComResult searchLastLog(String username) {
        SysLogininfor sysLogininfor = loginInfoMapper.selectLastLog(username);
        return new ComResult(2000,"查询成功",sysLogininfor);
    }
}
